<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
<link rel="stylesheet" href="../../lib/layui/css/layui.css" media="all">
    <style>
        .form-wrap{
            padding: 10px;
        }
    </style>
</head>
<body>
<div class="form-wrap">
    <!-- 新增商品规格参数表单 -->
    <form id="param_form" class="layui-form" method="post" enctype="multipart/form-data">
        <div class="layui-form-item">
            <label class="layui-form-label">参数名称</label>
            <div class="layui-input-block">
                <input id="paramName_input" name="paramName" type="text" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">参数拼音</label>
            <div class="layui-input-block">
                <input id="paramName_input" name="paramKey" type="text" placeholder="例如：保质期(baozhiqi)" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block"> 
                <button class="layui-btn" type="button" onclick="paramForm.submit()">提交</button>
            </div>
        </div>
    </form>
</div>
	<script src="../../publicjs/jquery-1.8.0.min.js"></script>
	<script src="../../publicjs/smallkingutil.js"></script>
	<script src="../../lib/layui/layui.js"></script>
<script type="text/javascript">
layui.use(['form', 'laydate'], function(){
    var form = layui.form,
    	layer = layui.layer;
	// 用户表单相关的操作对象
	window.paramForm = {
		submit : function() {
			var paramForm = document.getElementById("param_form");
			var formData = new FormData(paramForm);
			var	url, msg, data;
			if(this.paramId){
				url = "/beske/admin/commodity/param/update";
				msg = "修改";
				formData.set("paramId", this.paramId);
			}else{
				url = "/beske/admin/commodity/param/insert";
				msg = "新增";
			}
			var ajaxParam = {
				url : url
			}
			ajaxUtil.submitForm(formData, ajaxParam, function(data) {
				if (data.code == 200) {
					// 关闭当前的表单弹窗 刷新父级页面的数据表格
					var parentHtml = window.parent;
					parentHtml.layer.closeAll();
					parentHtml.paramTable.refresh();
				} else {
					layer.msg(msg + "失败，请联系开发人员。");
				}
			});
		}
	}
	
	var paramId = commonUtil.getRequestParam("paramId");
	if (paramId){
		paramForm.paramId = paramId;
		// 请求后台得到当前修改的用户数据，将其显示在表单里
		var ajaxParam = {
			url : '/beske/admin/commodity/param/detail',
			data : {
				paramId : paramId
			}
		}
		ajaxUtil.post(ajaxParam, function(data) {
			formUtil.setForm($('#param_form'), data.data);
			form.render("select");
		});
	}
	
});
</script>
<script>
	$(function(){
				commonUtil.setMaxLength(40);
			})
</script>
</body>
